<?php
namespace Common\Model;
use Think\Model;
use Think\Page;
use Common\Model\VRAdminModel;
class UserModel extends VRUserModel
{
	function getpage($pagesize=5){
		$count = $this->count();
		$p=new \Think\Page($count,$pagesize);
		$p->lastSuffix=false;
		$p->setConfig('prev','上一页');
		$p->setConfig('next','下一页');
		$p->setConfig('last','末页');
		$p->setConfig('first','首页');
		$p->parameter=I('get.');

		$this->limit($p->firstRow,$p->listRows);

		return $p;
	}

	//开启/禁用
	function setDisableStatus($id = null, $status){
		if($id){
			$data['status'] = $status;
			$rid = $this->where("user_id = ".$id)->data($data)->save();
			if($rid){
				return true;
			}
		}
		return false;
	}

	//查看详情
	function usermore($where){
		return $this->find($where);
	}

	//查询信息
	function search($start_time,$end_time,$phone,$nickname,$sex){
		if((!empty($nickname))&&(!empty($phone))&&(!empty($sex))){      //性别、手机号、昵称不为空
			$where['nickname'] = array('like',"%$nickname%");
			$where['mobile_phone'] = $phone;
			$where['sex'] = $sex;
		}elseif((!empty($nickname))&&(empty($phone))&&(!empty($sex))){	//手机号为空时
			$where['nickname'] = array('like',"%$nickname%");
			$where['sex'] = $sex;
		}elseif((!empty($nickname))&&(!empty($phone))&&(empty($sex))){	//性别为空时
			$where['nickname'] = array('like',"%$nickname%");
			$where['mobile_phone'] = $phone;
		}elseif((empty($nickname))&&(!empty($phone))&&(!empty($sex))){		//昵称为空时
			$where['mobile_phone'] = $phone;
			$where['sex'] = $sex;
		}elseif((empty($nickname))&&(!empty($phone))&&(empty($sex))){	//性别、昵称为空时
			$where['mobile_phone'] = $phone;
		}elseif((!empty($nickname))&&(empty($phone))&&(empty($sex))){	//性别、手机号为空时
			$where['nickname'] = array('like',"%$nickname%");
		}elseif((empty($nickname))&&(empty($phone))&&(!empty($sex))){	//手机号、昵称为空时
			$where['sex'] = $sex;
		}elseif((empty($nickname))&&(empty($phone))&&(empty($sex))){	//手机号、昵称、性别为空时
			$where = array();
		}
		//查询内容
		if(!empty($start_time)){          //开始时间不为空，结束时间为空
			if(!empty($end_time)){        //开始时间不为空，结束时间不为空
				 return $sel=$this->where($where)->where("register_time between '$start_time' and '$end_time'")->select();
			}else{						  //开始时间不为空，结束时间为空
				return $sel=$this->where($where)->where("register_time > '$start_time'")->select();
			}
		}else{
			if(!empty($end_time)){        //开始时间为空，结束时间不为空 
				return $sel=$this->where($where)->where("register_time < '$end_time'")->select();
			}else{						//开始时间为空，结束时间为空
				return $sel=$this->where($where)->select();
			}
		}
	}
}